
package de.unihannover.se.restlab.microblog.models;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "account")
@XmlAccessorType(XmlAccessType.FIELD)
public class Account {

	private static int idCounter = 0;

	@XmlElement
	private int accountId;

	@XmlElement
	private User user;

	@XmlElement
	private Role role;

	@XmlElement
	private String password;

	@XmlElementRef
	private Link self;

	public Account (User u, Role r, String p) {
		user = u;
		role = r;
		password = p;
		accountId = idCounter++;
	}

	public Account (User u, Role r) {
		this(u, r, "0000");
	}

	public Account () {
// this(null, Role.User, "0000");
	}

	public Account (de.unihannover.se.restlab.microblog.jpamodels.Account a) {
		accountId = a.getAccountId();
		user = new User(a.getUser());
		role = a.getRole();
		password = a.getPassword();
	}

	public User getUser () {
		return user;
	}

	public void setUser (User user) {
		this.user = user;
	}

	public Role getRole () {
		return role;
	}

	public void setRole (Role role) {
		this.role = role;
	}

	public String getPassword () {
		return password;
	}

	public void setPassword (String password) {
		this.password = password;
	}

	public int getAccountId () {
		return accountId;
	}

	public Link getSelf () {
		return self;
	}

	public void setSelf (Link self) {
		this.self = self;
	}

	public void setAccountId (int accountId) {
		this.accountId = accountId;
	}

	@Override
	public String toString () {
		return "Account [accountId=" + accountId + ", user=" + user + ", role=" + role + "]";
	}

	private de.unihannover.se.restlab.microblog.jpamodels.Account persistence = new de.unihannover.se.restlab.microblog.jpamodels.Account();

	public de.unihannover.se.restlab.microblog.jpamodels.Account getPersistence () {
		persistence.setAccountId(accountId);
		persistence.setPassword(password);
		persistence.setRole(role);
		persistence.setUser(user.getPersistence());
		return persistence;
	}

}
